<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //onkeyup 按下松开的时候触发
        document.addEventListener('keyup', function() {
            console.log('up:' + '1.松开了!');
        })

        //onkeydown 按下的时候触发
        document.addEventListener('keydown', function() {
            console.log('down:' + '2.按下了!');
        })

        //onkeypress 按下的时候触发 功能键没有作用: ctrl、shift
        document.addEventListener('keypress', function() {
            console.log('press:' + '3.松开了!');
        })
    </script>
</body>
</html>